import { MenuItemDefinition } from '@amcax/base';
import { wsApi } from '../../../../../../server';
import { ProductTreeNode } from '../../types';

export const removeTranslucency: MenuItemDefinition<ProductTreeNode> = {
  id: 'removeTranslucency',
  children: '移除半透明',
  hidden: ({ props: { color, type } }) =>
    type !== 'part' ||
    color === undefined ||
    color?.all === undefined ||
    color?.all?.a === undefined ||
    color?.all?.a >= 1.0,
  onClick: async ({ props: node }) => {
    if (node.type === 'part') {
      const info = node.color?.all;
      const property: { opacity?: number; color?: string } = {};
      if (info?.c) {
        property.color = info.c;
        property.opacity = 1.0;
      } else {
        property.opacity = 1.0;
      }
      await wsApi.setColorAndOpacity([node.key + ':all'], [property]);
    }
  },
};
